package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.StockFlowBillEntity;
import com.xbongbong.saas.domain.entity.StockFlowBillEntityExt;
import com.xbongbong.saas.domain.entity.StockFlowBillUpdateEntity;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface StockFlowBillModel {
    /**
     * 入库单产品数据插入
     * @param stockFlowBillEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return Integer
     */
    Integer insert(StockFlowBillEntity stockFlowBillEntity) throws XbbException;
    /**
     * 入库单产品数据更新
     * @param stockFlowBillEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @throws XbbException 异常
     * @return Integer
     */
    Integer update(StockFlowBillEntity stockFlowBillEntity) throws XbbException;

    /**
     * 根据索引查询数据
     *
     * @param param 查询参数
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return List<ProductEntityExt>
     **/
    List<StockFlowBillEntity> findEntitys(Map<String, Object> param);

    /**
     * 查询列表数量
     *
     * @param param
     * @return Integer
     * @author lee
     * @date 2020/4/13 16:07
     * @descption
     */
    Integer getEntitysCount(Map<String, Object> param);

    Integer save(StockFlowBillEntity stockFlowBillEntity);

    void insertBatch(List<StockFlowBillEntity> stockFlowBillEntityList) throws XbbException;

    /**
     * 更新单个单据日期后的库存和成本
     * @param corpid
     * @param warehouseKeyList
     * @return
     */
    Integer updateGreaterThanTime(Collection<StockFlowBillUpdateEntity> updateList, String corpid, Set<String> warehouseKeyList);

    /**
     * 获取筛选时间内最新的结存记录
     * @param param
     * @return
     */
    List<StockFlowBillEntity> getLatestFlowBillByWarehouseKey(Map<String, Object> param);

    Integer deleteByRefIdIn(String corpid, List<Long> refIdIn, List<Integer> businessTypeIn);

    /**
     * 获取期间的出入库汇总信息
     * @param param
     * @return
     */
    List<StockFlowBillEntityExt> getFlowInfo(Map<String, Object> param);

    /**
     * 查询分组后计数
     *
     * @param param
     * @return Integer
     * @author lee
     * @date 2020/4/13 16:07
     * @descption
     */
    Integer getGroupByEntitysCount(Map<String, Object> param);

    void updateBatch(Collection<StockFlowBillUpdateEntity> updateList, String corpid, Set<String> warehouseKeyList);

    void deleteAllByCorpId(String corpid);

    List<StockFlowBillEntity> queryStockFlowbydate(Map<String, Object> param);

    void updateStockFlowById(List<StockFlowBillEntity> stockFlowBillEntityList, String corpid);

    List<StockFlowBillEntity> queryStockFlowbydateAndId(String corpid, Long date, List<Long> productId);

    /**
     * 流水中是否存在产品
     *
     * @param corpid        公司ID
     * @param productIdList 产品ID
     * @return true -> 存在产品流水， false->不存在
     */
    Boolean isExistProductIn(String corpid, List<Long> productIdList);

    void deleteByAddTime(Map<String, Object> param);

    List<StockFlowBillEntity> getStockFlowByWarehouseKey(String corpid, List<String> warehouseKeyList);

    StockFlowBillEntity getStockFlowBillBytime(String corpid, Long productId, Long warehouseId);

    StockFlowBillEntity checkDate(String corpid,Long date,List<Long> productIdList);

    List<StockFlowBillEntity> getCheckDate(String corpid,Long date,List<Long> productIdList);

    StockFlowBillEntity getFirstStockFlowBillBytime(String corpid,Long date);
}
